//
//  ViewController.m
//  RuntimeDemo
//
//  Created by hfzhangzhang on 2018/3/27.
//  Copyright © 2018年 hfzhangzhang. All rights reserved.
//

#import "ViewController.h"
#import <objc/message.h>
#import "Person.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    Person *p = objc_msgSend(Person.class, @selector(alloc));
    p = objc_msgSend(p, sel_registerName("init"));
   //msg 设置成NO不然报错
    objc_msgSend(p, @selector(eat));
    
    unsigned int count = 0;
    //查看一个类的所有属性列表
    // copy new creat 代表着会在堆区（malloc）开辟空间
    Ivar *ivarList =  class_copyIvarList(Person.class, &count);
    // ivarList在栈区，指向的是在堆区首地址
    Ivar ivar = ivarList[0];
    const char * name= ivar_getName(ivar);
    NSLog(@"%s",name);
    
    
    free(ivarList);
  
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
